package com.模板方法模式.方法模板;

import java.util.function.Consumer;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/7/7 10:12
 * @description:
 * @version:
 */
public class Test {
    public static void main(String[] args) {
        //初始化一个泛型方法类
        Algo<Integer> obj = new Algo<>();
        //初始化一个ILess的子类对象 int类型的比较器
        ILess<Integer> cmp = new InteLess();
        Integer a[] = {3,5,2,7};
        //传入一个比较数组，传入一个比较器
        Integer max = obj.getMax(a,cmp);
        System.out.println("最大值是："+max);

        Algo<Student> obj2 = new Algo<>();
        ILess<Student> cmp2 = new StudLess();
        Student s[] = {new Student("zy",89),new Student("smm",96),new Student("minmin",84)};
        Student max2 = obj2.getMax(s, cmp2);
        System.out.println(max2.name+"的成绩最高，是："+max2.grade);


        //自定义测试
        Blgo<Integer> testB = new Blgo<>();
        Consumer<Integer> consumer1 = new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                System.out.println(integer.intValue());
            }
        };
        testB.getValue(a,consumer1);

        Blgo<Student> testB2 = new Blgo<>();
        Consumer<Student> consumer2 = student -> System.out.println(student.toString());
        testB2.getValue(s,consumer2);



    }
}
